#pragma once


namespace stl
{
	template<class Map>	const typename Map::mapped_type&
	find_in_map(const Map& container, typename Map::key_type key, const typename Map::mapped_type& def_res)
	{
		Map::const_iterator it = container.find(key);
		return (it != container.end()) ? it->second : def_res;
	}

	template<class Container>
	bool find_and_remove(Container& container, const typename Container::value_type& val)
	{
		Container::const_iterator it = std::find(container.begin(), container.end(), val);
		bool exist = (it != container.end());
		if (exist)
			container.erase(it);

		return exist;
	}

	template<class Container>
	bool push_back_unique(Container& container, const typename Container::value_type& val)
	{
		Container::const_iterator it = std::find(container.begin(), container.end(), val);
		bool exist = (it != container.end());
		if (!exist)
			container.push_back(val);

		return !exist;
	}
};